package com.haibara.aioj.rabbitmq.init;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

// RabbitMQ初始化
public class MqInitMain {
    public static void main(String[] args) {
        try {
            // 创建交换机
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
//            factory.setVirtualHost("..."); 设置VirtualHost
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            String EXCHANGE_NAME = "aioj_exchange";
            channel.exchangeDeclare(EXCHANGE_NAME,"direct");

            //创建队列
            String queueName = "aioj_queue";
            channel.queueDeclare(queueName,true,false,false,null);
            channel.queueBind(queueName,EXCHANGE_NAME,"aioj");
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
